﻿<script src="~/admui-13945148017-1592211513218/public/vendor/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/bootstrap-datepicker/bootstrap-datepicker.zh-CN.min.js"></script>

<link href="~/admui-13945148017-1592211513218/public/css/examples/tables/datatable.css" rel="stylesheet" />
<link href="~/admui-13945148017-1592211513218/public/vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet" />
<link href="~/admui-13945148017-1592211513218/public/vendor/datatables-bootstrap/dataTables.bootstrap4.css" rel="stylesheet" />
<link href="~/admui-13945148017-1592211513218/public/vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet" />
<script src="~/admui-13945148017-1592211513218/public/vendor/datatables/jquery.dataTables.min.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/datatables-bootstrap/dataTables.bootstrap.min.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/datatables-bootstrap/dataTables.bootstrap4.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/datatables-responsive/dataTables.responsive.min.js"></script>
<form id="form1" runat="server">
    <div class="page-container" id="admui-pageContent">
        <div class="page animation-fade page-forms">
            <div class="page-header">
                <h1 class="page-title" id="biao1"></h1>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item">
                        <a class="icon wb-home" href="javascript:;">公司管理</a>
                    </li>
                    <li class="breadcrumb-item active" id="biao2"></li>
                </ol>
                <label style="display:none" id="lbl_Id"></label>
            </div>
            <div class="page-content">
                <div class="panel">
                    <div class="panel-body container-fluid">
                        <h4 class="example-title"></h4>
                        <div class="row">
                            <div class="form-group col-sm-1"></div>
                            <div class="form-group col-sm-5">
                                <label class="control-label" for="inputBasicPassword">公司名称</label>
                                <input type="text" class="form-control" id="ipt_GongSiMingCheng" name="" placeholder="请输入公司名称" autocomplete="off" />
                            </div>
                            <div class="form-group col-sm-5">
                                <label class="control-label" for="inputBasicPassword">成立时间</label>
                                <input type="text" class="form-control empty" autocomplete="off" data-date-format="yyyy-mm-dd" name="" id="ipt_ChengLiShiJian" data-plugin="datepicker" data-language="zh-CN" placeholder="请输入成立时间" />
                            </div>
                            <div class="form-group col-sm-1"></div>
                            <div class="form-group col-sm-1"></div>
                            <div class="form-group col-sm-5">
                                <label class="control-label" for="inputBasicPassword">公司地址</label>
                                <input type="text" class="form-control" id="ipt_GongSiDiZhi" name="" placeholder="请输入公司地址" autocomplete="off" />
                            </div>
                            <div class="form-group col-sm-5">
                                <label class="control-label" for="inputBasicPassword">联系方式</label>
                                <input type="text" class="form-control" id="ipt_LianXiFangShi" name="" placeholder="请输入联系方式" autocomplete="off" />
                            </div>
                            <div class="form-group col-sm-1"></div>
                            @*<div class="form-group col-sm-1"></div>
                                <div class="form-group col-sm-5">
                                    <label class="control-label" for="inputBasicPassword">负责人</label>
                                    <select class="form-control" id="slt_FuZeRen" name="" data-fv-notempty="true" data-fv-field="requiredSelect"></select>
                                </div>
                                <div class="form-group col-sm-5">
                                    <label class="control-label" for="inputBasicPassword">法人</label>
                                    <select class="form-control" id="slt_FaRen" name="" data-fv-notempty="true" data-fv-field="requiredSelect"></select>
                                </div>
                                <div class="form-group col-sm-1"></div>*@
                            <div class="form-group col-sm-1"></div>
                            <div class="form-group col-sm-5">
                                <label class="control-label" for="inputBasicPassword">法人</label>
                                <input type="text" class="form-control" id="slt_FaRen" name="" placeholder="请输入法人" autocomplete="off" />
                            </div>
                            <div class="form-group col-sm-5">
                                <label class="control-label" for="inputBasicPassword">公司规模</label>
                                <input type="text" class="form-control" id="ipt_GongSiGuiMo" name="" placeholder="请输入公司规模" autocomplete="off" />
                            </div>
                            <div class="form-group col-sm-1"></div>
                            <div class="form-group col-sm-1"></div>
                            <div class="form-group col-sm-10">
                                <label class="control-label" for="inputBasicPassword">公司简介</label>
                                <textarea rows="5" class="form-control" id="ipt_GongSiJianJie" placeholder="请输入公司简介"></textarea>
                            </div>
                            <div class="form-group col-sm-1"></div>
                            <div class="form-group col-sm-1"></div>
                            <div class="form-group col-sm-5">
                                <label class="control-label" for="inputBasicPassword">官方网站</label>
                                <input type="text" class="form-control" id="ipt_GuanFangWangZhan" name="" placeholder="请输入官方网站" autocomplete="off" />
                            </div>
                            <div class="form-group col-sm-5 row" style="padding-top:30px">
                                <div class="form-group col-sm-6">
                                    <button type="button" id="anniu1" class="btn btn-block btn-success" style="width: 100%; margin-left: 15px; float: left;" onclick="GongSi();"></button>
                                </div>
                                <div class="form-group col-sm-6">
                                    <button type="button" id="anniu2" class="btn btn-outline btn-success" style="width: 100%;" onclick="FanHuChongZhi();"></button>
                                </div>
                            </div>
                            <div class="form-group col-sm-1"></div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</form>
<script type="text/javascript" language="javascript" class="init">
    $(document).ready(function () {
        $("#SpanGongSi").click();
        //人员下拉框(没用)
        RenYuanBD();
        //获取Id
        var Id = GetQueryString("Id");
        //修改样式
        XiuGaiYangShi(Id);
    })
    //获取Id
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
    //修改样式 和调用绑定
    function XiuGaiYangShi(Id) {
        if (Id != null) {
            $("#biao1").text("修改公司");
            $("#biao2").text("修改公司");
            $("#anniu1").text("修改公司");
            $("#anniu2").text("取消");
            BangDingGongSiXinXi(Id);
        } else {
            $("#biao1").text("添加公司");
            $("#biao2").text("添加公司");
            $("#anniu1").text("+添加公司");
            $("#anniu2").text("重置");
        }
    }
    //人员下拉框(没用)
    function RenYuanBD() {
        //$.ajax({
        //    type: 'POST',
        //    url: '../GongSi/GetSelRenYuan',
        //    dataType: 'json',
        //    data: {},
        //    success: function (date) {
        //        console.log(date)
        //        var XLK = $("#slt_FuZeRen");
        //        var XLK2 = $("#slt_FaRen");
        //        XLK.append("<option value='0'>请选择</option>");
        //        XLK2.append("<option value='0'>请选择</option>");
        //        $(date).each(function (key) {
        //            var opt = $("<option></option>").text(date[key].XingMing).val(date[key].Id);
        //            var opt2 = $("<option></option>").text(date[key].XingMing).val(date[key].Id);
        //            XLK.append(opt);
        //            XLK2.append(opt2);
        //        })
        //    },
        //});
    }
    //添加修改公司信息
    function GongSi() {
        var Id = GetQueryString("Id");
        //判断是添加或是修改
        if (Id != null) {
            var url = '../GongSi/Update';
        } else {
            var url = '../GongSi/Add';
        }
        if ($("#ipt_GongSiMingCheng").val() == "" || $("#ipt_GongSiMingCheng").val() == null || $("#ipt_GongSiMingCheng").val() == undefined) {
            alert('请填写公司名称');
        } else if ($("#ipt_ChengLiShiJian").val() == "" || $("#ipt_ChengLiShiJian").val() == null || $("#ipt_ChengLiShiJian").val() == undefined) {
            alert('请选择成立时间');
        } else if ($("#ipt_GongSiDiZhi").val() == "" || $("#ipt_GongSiDiZhi").val() == null || $("#ipt_GongSiDiZhi").val() == undefined) {
            alert('请填写公司名称');
        } else if ($("#ipt_LianXiFangShi").val() == "" || $("#ipt_LianXiFangShi").val() == null || $("#ipt_LianXiFangShi").val() == undefined) {
            alert('请填写联系方式');
        }
        //else if ($("#slt_FuZeRen").find("option:selected").val() == "请选择" || $("#slt_FuZeRen").find("option:selected").val() == "0") {
        //    alert('请选择负责人');
        //}
        else if ($("#slt_FaRen").val() == "" || $("#slt_FaRen").val() == null || $("#slt_FaRen").val() == undefined) {
            alert('请选择法人');
        } else if ($("#ipt_GongSiGuiMo").val() == "" || $("#ipt_GongSiGuiMo").val() == null || $("#ipt_GongSiGuiMo").val() == undefined) {
            alert('请填写公司规模');
        } else if ($("#ipt_GuanFangWangZhan").val() == "" || $("#ipt_GuanFangWangZhan").val() == null || $("#ipt_GuanFangWangZhan").val() == undefined) {
            alert('请填写官方网址');
        } else if ($("#ipt_GongSiJianJie").val() == "" || $("#ipt_GongSiJianJie").val() == null || $("#ipt_GongSiJianJie").val() == undefined) {
            alert('请填写公司简介');
        } else {
            $.ajax({
                url: '' + url + '',
                data: { Id: Id, ipt_GongSiMingCheng: $("#ipt_GongSiMingCheng").val(), ipt_ChengLiShiJian: $("#ipt_ChengLiShiJian").val(), ipt_GongSiDiZhi: $("#ipt_GongSiDiZhi").val(), ipt_LianXiFangShi: $("#ipt_LianXiFangShi").val(), /*slt_FuZeRen: $("#slt_FuZeRen").find("option:selected").val(),*/ slt_FaRen: $("#slt_FaRen").val(), ipt_GongSiGuiMo: $("#ipt_GongSiGuiMo").val(), ipt_GuanFangWangZhan: $("#ipt_GuanFangWangZhan").val(), ipt_GongSiJianJie: $("#ipt_GongSiJianJie").val() },
                type: "post",
                dataType: "text",
                success: function (response) {
                    if (response != -1) {
                        location.href = "../GongSi/GongSiList?Id=" + response;
                    } if (response == "失败") {
                        if (Id != null) {
                            alert('修改公司失败，请确认填写信息无误后及时联系管理员！谢谢~');
                        } else {
                            alert('添加公司失败，请确认填写信息无误后及时联系管理员！谢谢~');
                        }
                        
                    }
                }
            });
        }
    }
    //返回重置
    function FanHuChongZhi() {
        var Id = GetQueryString("Id");
        if (Id != null) {
            location.href = "../GongSi/GongSiList";
        } else {
            $("#ipt_GongSiMingCheng").val('');
            $("#ipt_ChengLiShiJian").val('');
            $("#ipt_GongSiDiZhi").val('');
            $("#ipt_LianXiFangShi").val('');
            //$("#slt_FuZeRen").val(0);
            $("#slt_FaRen").val('');
            $("#ipt_GongSiGuiMo").val('');
            $("#ipt_GuanFangWangZhan").val('');
            $("#ipt_GongSiJianJie").val('');
        }
    }
    //绑定公司信息
    function BangDingGongSiXinXi(Id) {
        $.ajax({
            url: '../GongSi/GetById',
            data: { Id: Id },
            type: "post",
            dataType: "json",
            success: function (response) {
                console.log(response);
                $(response).each(function (key) {
                    console.log(response[key].Id);
                    $("#ipt_GongSiMingCheng").val(response[key].GongSiMingCheng);
                    $("#ipt_ChengLiShiJian").val(response[key].ChengLiShiJian);
                    $("#ipt_GongSiDiZhi").val(response[key].GongSiDiZhi);
                    $("#ipt_LianXiFangShi").val(response[key].LianXiFangShi);
                    //$("#slt_FuZeRen").val(response[key].t_RenYuanBiao_FuZeRen.Id);
                    $("#slt_FaRen").val(response[key].FaRen);
                    $("#ipt_GongSiGuiMo").val(response[key].GongSiGuiMo);
                    $("#ipt_GuanFangWangZhan").val(response[key].GuanFangWangZhan);
                    $("#ipt_GongSiJianJie").val(response[key].GongSiJianJie);
                })
            }
        });
    }
</script>
